
::进入当前目脚本目录
cd /d %~dp0

::查找是否有esptool安装成功
@echo off
set  findcmd=esptool.py.exe
for %%I in ( %findcmd% ) do IF EXIST %%~$PATH:I ( echo %%~$PATH:I&goto end ) ELSE ( echo %%I is not found in PATH!&goto nopyexe )
:nopyexe
@echo off
set findcmd=esptool.exe
for %%I in ( %findcmd% ) do IF EXIST %%~$PATH:I ( echo %%~$PATH:I&goto end ) ELSE ( echo %%I is not found in PATH!&goto noexe )
:noexe
echo "not find esptool"
pause
exit /b "erro not find esptool.exe or esptool.py.exe"
:end

%findcmd% -b 115200 erase_flash

%findcmd% --chip esp32 --baud 115200 write_flash -z 0x1000 esp32-espnow-g20-v1.19.1-6-g44f65965b-GENERIC.bin

echo "upload file"
python.exe uploadpyfile.py

upload.bat

cd /d %~dp0

::重启设备
%findcmd% run

pause